Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
26 lines (23 loc) · 722 Bytes

1.7.11 - 1.7.5 swoole_client支持sendfile接口.md

File metadata and controls

26 lines (23 loc) · 722 Bytes

1.7.5 swoole_client支持sendfile接口

1.7.5增加了swoole_client->sendfile接口,在客户端中也可以直接发送一个文件到服务器。使用方法

$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC); //同步阻塞
if (!$client->connect('127.0.0.1', 9501, -1))
{
	exit("connect failed. Error: {$client->errCode}\n");
}
if ($client->sendfile(__DIR__.'/test.txt') === false)
{
	echo "send failed. Error: {$client->errCode}\n";
	break;
}
$data = $client->recv(7000);
if ($data === false)
{
	echo "recv failed. Error: {$client->errCode}\n";
	break;
}
var_dump($data);
$client->close();

sendfile只需要传入文件名即可发送到服务器。当文件不存在时会返回false。